<?php class receive_update extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function insert($arr){
       $result = $this->db->insert('receive_update',$arr);
       return $result;
    }
    
    function getreceive_array($arr){
       $this->db->where($arr);
       $this->db->order_by("receive_id", "desc");
       $query = $this->db->get('receive_update');
       $result = $query->result(); 
       return $result;
    }
    
    function select($id,$num="",$offset=""){
       $this->db->limit($num,$offset);	
       if($id!=""){
       	  $this->db->where(array('receive_id'=>$id));
       }
       $query = $this->db->get('receive_update');
       $result = $query->result(); 
       return $result;
    }
    function select_by_array($array){
       $this->db->where($array);
       $this->db->order_by('receive_id','desc');
       $query = $this->db->get('receive_update');       
       $result = $query->result(); 
       return $result;
    }
    
    function getlast($version_id,$id){
       $this->db->where(array('category_id'=>$version_id,'version_id'=>$id));
       $this->db->select_sum('count');
       $query = $this->db->get('receive_update');
       $result = $query->result(); 
       return $result;
    }
    
    function update($id){
       $this->version_id = $_POST['version_id'];
       $this->category_id = $_POST['category_id'];
       $this->mod_id = $_POST['mod_id'];
       $this->count = $_POST['count'];
       if(!isset($_POST['codes'])){
         $this->codes = $_POST['codes'];
       }
       if(!isset($_POST['contacter'])){
         $this->contacter = $_POST['contacter'];
       }
       $result = $this->db->update('receive_update',$this,array('receive_id'=>$id));
       return $result;
    }
    
    function update_ar($array,$id){
       $result = $this->db->update('receive_update',$array,array('receive_id'=>$id));
       return $result;
    }
    
    
    function del($id){
       $result = $this->db->delete('receive_update',array('receive_id'=>$id));
       return $result;
    }
}